using DynamicProxies;
using DynamicProxies.Tests.Types;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace DynamicProxies.Tests
{
	[TestClass]
	public sealed class SuppressExceptionTests : BaseTests
	{
		private bool suppress;

		protected override sealed void OnSetup()
		{
			this.suppress = false;
		}

		[TestMethod, ExpectedException(typeof(NotImplementedException))]
		public void DoNotSuppressExceptionAfterCall()
		{
			Proxy.Create<ExceptionalClass>(this).Unsafe();
		}

		[TestMethod]
		public void SuppressExceptionAfterCall()
		{
			this.suppress = true;
			Proxy.Create<ExceptionalClass>(this).Unsafe();
		}

		protected override sealed bool OnAfterMethodInvocation(MethodBase target, object[] arguments, ref object returnValue, Exception generatedException)
		{
			return !this.suppress;
		}
	}
}
